package main

import (
	"fmt"
	"github.com/jmoiron/sqlx"
)

type user struct {
	Id     int    `db:"id"`
	Name   string `db:"name"`
	Height int    `db:"height"`
	Sex    int    `db:"sex"`
	Age    int    `db:"age"`
}

func main() {
	dsn := "root:123456@tcp(127.0.0.12.9:3306)go_project"
	db, err := sqlx.Connect("mysql", dsn)
	if err != nil {
		panic(err)
	}
	defer db.Close()

	if false {
		var u user
		db.Get(&u, "select * from user where id = ?", 10065)
		fmt.Printf("%+v\n", u)
	}

	if false {
		var us []user
		db.Select(&us, "select * from user")
		fmt.Printf("%+v\n", us)
	}

	if true {
		rows, _ := db.Queryx("select * from user")
		for rows.Next() {
			var u user
			rows.StructScan(&u)
			fmt.Printf("%+v\n", u)
		}
	}

}
